package com.sxtbbs.util;

import java.io.InputStream;
import java.util.Properties;

import com.sxtbbs.dao.DBDao;
import com.sxtbbs.dao.UserDao;

/**
 * 工厂模式创建UserDao实例
 * @author lovemanai
 *
 */
public class UserDaoFactory {
	private static Properties p = null;
		
	static {
		try {
			p = new Properties();
			InputStream in = DBDao.class.getClassLoader().
					getResourceAsStream("daoconfig.properties");
			p.load(in);
		} catch(Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	@SuppressWarnings("rawtypes")
	public static UserDao getUserDao() {
		UserDao userDao = null;
		try {
		String className = p.getProperty("com.sxtbbs.dao.UserDao");
		Class clazz = Class.forName(className);
		userDao = (UserDao)clazz.newInstance();
		} catch(Exception e) {
			throw new RuntimeException(e);
		}
		return userDao;
	}
}
